﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;


namespace Fast.Framework.Utils
{
    /// <summary>
    /// 动态条件表达式工具类
    /// </summary>
    public static class Expression
    {
        #region T
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam
        /// <returns></returns>
        public static Expression<T> Create<T>() where T : class, new()
        {
            return new Expression<T>();
        }
        #endregion

        #region T2
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2> Create<T, T2>() where T : class, new() where T2 : class, new()
        {
            return new Expression<T, T2>();
        }
        #endregion

        #region T3
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3> Create<T, T2, T3>() where T : class, new() where T2 : class, new() where T3 : class, new()
        {
            return new Expression<T, T2, T3>();
        }
        #endregion

        #region T4
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4> Create<T, T2, T3, T4>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new()
        {
            return new Expression<T, T2, T3, T4>();
        }
        #endregion

        #region T5
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5> Create<T, T2, T3, T4, T5>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5>();
        }
        #endregion

        #region T6
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6> Create<T, T2, T3, T4, T5, T6>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6>();
        }
        #endregion

        #region T7
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7> Create<T, T2, T3, T4, T5, T6, T7>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7>();
        }
        #endregion

        #region T8
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="T8"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7, T8> Create<T, T2, T3, T4, T5, T6, T7, T8>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7, T8>();
        }
        #endregion

        #region T9
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="T8"></typeparam>
        /// <typeparam name="T9"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7, T8, T9> Create<T, T2, T3, T4, T5, T6, T7, T8, T9>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7, T8, T9>();
        }
        #endregion

        #region T10
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="T8"></typeparam>
        /// <typeparam name="T9"></typeparam>
        /// <typeparam name="T10"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Create<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new() where T10 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>();
        }
        #endregion

        #region T11
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="T8"></typeparam>
        /// <typeparam name="T9"></typeparam>
        /// <typeparam name="T10"></typeparam>
        /// <typeparam name="T11"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Create<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new() where T10 : class, new() where T11 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>();
        }
        #endregion

        #region T12
        /// <summary>
        /// 创建
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <typeparam name="T3"></typeparam>
        /// <typeparam name="T4"></typeparam>
        /// <typeparam name="T5"></typeparam>
        /// <typeparam name="T6"></typeparam>
        /// <typeparam name="T7"></typeparam>
        /// <typeparam name="T8"></typeparam>
        /// <typeparam name="T9"></typeparam>
        /// <typeparam name="T10"></typeparam>
        /// <typeparam name="T11"></typeparam>
        /// <typeparam name="T12"></typeparam>
        /// <returns></returns>
        public static Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Create<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>() where T : class, new() where T2 : class, new() where T3 : class, new() where T4 : class, new() where T5 : class, new() where T6 : class, new() where T7 : class, new() where T8 : class, new() where T9 : class, new() where T10 : class, new() where T11 : class, new() where T12 : class, new()
        {
            return new Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
        }
        #endregion
    }

    #region T
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Expression<T>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T> And(System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T> Or(System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T2
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public class Expression<T, T2>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2> And(System.Linq.Expressions.Expression<Func<T, T2, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2> Or(System.Linq.Expressions.Expression<Func<T, T2, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, bool>>(bodyExpression, parameters);
            return expression;
        }
    }
    #endregion

    #region T3
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    public class Expression<T, T2, T3>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3> And(System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T4
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    public class Expression<T, T2, T3, T4>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T5
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    public class Expression<T, T2, T3, T4, T5>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T6
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T7
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T8
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    /// <typeparam name="T8"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7, T8>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T8), "h"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, T8, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T9
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    /// <typeparam name="T8"></typeparam>
    /// <typeparam name="T9"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7, T8, T9>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T8), "h"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T9), "i"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T10
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    /// <typeparam name="T8"></typeparam>
    /// <typeparam name="T9"></typeparam>
    /// <typeparam name="T10"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T8), "h"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T9), "i"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T10), "j"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T11
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    /// <typeparam name="T8"></typeparam>
    /// <typeparam name="T9"></typeparam>
    /// <typeparam name="T10"></typeparam>
    /// <typeparam name="T11"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T8), "h"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T9), "i"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T10), "j"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T11), "k"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion

    #region T12
    /// <summary>
    /// 动态条件表达式
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    /// <typeparam name="T4"></typeparam>
    /// <typeparam name="T5"></typeparam>
    /// <typeparam name="T6"></typeparam>
    /// <typeparam name="T7"></typeparam>
    /// <typeparam name="T8"></typeparam>
    /// <typeparam name="T9"></typeparam>
    /// <typeparam name="T10"></typeparam>
    /// <typeparam name="T11"></typeparam>
    /// <typeparam name="T12"></typeparam>
    public class Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>
    {

        /// <summary>
        /// 参数
        /// </summary>
        private readonly List<ParameterExpression> parameters;

        /// <summary>
        /// body表达式
        /// </summary>
        private System.Linq.Expressions.Expression bodyExpression;

        /// <summary>
        /// 构造方法
        /// </summary>
        public Expression()
        {
            parameters = new List<ParameterExpression>();
        }

        /// <summary>
        /// 拼接
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <param name="expressionType">表达式类型</param>
        private void Splicing(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> expression, ExpressionType expressionType)
        {
            if (parameters.Count == 0)
            {
                parameters.AddRange(expression.Parameters);
            }
            if (bodyExpression == null)
            {
                bodyExpression = expression.Body;
            }
            else
            {
                if (expressionType == ExpressionType.AndAlso)
                {
                    bodyExpression = System.Linq.Expressions.Expression.AndAlso(bodyExpression, expression.Body);
                }
                if (expressionType == ExpressionType.OrElse)
                {
                    bodyExpression = System.Linq.Expressions.Expression.OrElse(bodyExpression, expression.Body);
                }
            }
        }

        /// <summary>
        /// 和
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> And(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> expression)
        {
            Splicing(expression, ExpressionType.AndAlso);
            return this;
        }

        /// <summary>
        /// 和如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> AndIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.AndAlso);
            }
            return this;
        }

        /// <summary>
        /// 或
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Or(System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> expression)
        {
            Splicing(expression, ExpressionType.OrElse);
            return this;
        }

        /// <summary>
        /// 或如果
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="expression">表达式</param>
        /// <returns></returns>
        public Expression<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> OrIF(bool where, System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> expression)
        {
            if (where)
            {
                Splicing(expression, ExpressionType.OrElse);
            }
            return this;
        }

        /// <summary>
        /// 构建
        /// </summary>
        /// <returns></returns>
        public System.Linq.Expressions.Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>> Build()
        {
            if (bodyExpression == null)
            {
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T), "a"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T2), "b"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T3), "c"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T4), "d"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T5), "e"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T6), "f"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T7), "g"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T8), "h"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T9), "i"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T10), "j"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T11), "k"));
                parameters.Add(System.Linq.Expressions.Expression.Parameter(typeof(T12), "l"));
                bodyExpression = System.Linq.Expressions.Expression.Constant(true);
            }
            var expression = System.Linq.Expressions.Expression.Lambda<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, bool>>(bodyExpression, parameters.ToArray());
            return expression;
        }
    }
    #endregion
}